﻿using BoriPeter.FitnessJournal8.Models;
using BoriPeter.NutritionFileSource.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BoriPeter.NutritionFileSource.Converters
{
    public static class HistoryConverter
    {
        #region Food 2 HistoryItem
        public static Food Convert(this HistoryItem _historyItem)
        {
            Food food = new Food();

            food.Name = _historyItem.Name;
            food.Brand = _historyItem.Brand;
            food.Id = _historyItem.Id;
            food.ImageName = _historyItem.Image;
            food.VisitedFrequency = _historyItem.Frequency;
            food.LastAccessedDate = _historyItem.Date;

            return food;
        }
        #endregion

        #region List<Food> 2 List<HistoryItem>
        public static List<Food> Convert(this IEnumerable<HistoryItem> _historyList)
        {
            List<Food> list = new List<Food>();
            foreach (var item in _historyList)
            {
                list.Add(item.Convert());
            }
            return list;
        }
        #endregion

        #region HistoryItem 2 Food
        public static HistoryItem Convert(this Food _food)
        {
            HistoryItem history = new HistoryItem();

            history.Brand = _food.Brand;
            history.Date = _food.LastAccessedDate;
            history.Frequency = _food.VisitedFrequency;
            history.Id = _food.Id;
            history.Image = _food.ImageName;
            history.Name = _food.Name;

            return history;
        }
        #endregion

        #region List<HistoryItem> 2 List<Food>
        public static List<HistoryItem> Convert(this IEnumerable<Food> _list)
        {
            List<HistoryItem> historyList = new List<HistoryItem>();

            foreach (var item in _list)
            {
                historyList.Add(item.Convert());
            }

            return historyList;
        }
        #endregion
    }
}
